package application;

import java.io.Serializable;

import application.messages.Message;

/**
 * Abstract class which should implement each runnable component (like menu and game).
 * 
 * @author Tomas Zima
 */
public abstract class RunnableComponent implements Serializable
{
	/**
	 * Makes component activated. 
	 */
	public void	run()
	{
		if (isActive() == false)
		{
			this.active = true;
			this.onActivation();
		}
	}
	
	/**
	 * Makes component deactivated.
	 */
	public void	stop()
	{
		if (isActive() == true)
		{
			this.active = false;
			this.onDeactivation();
		}
	}
	
	/**
	 * Checks if component is activated.
	 * 
	 * @return
	 * 	Is true if activated, false if it's not.
	 */
	public boolean isActive()
	{
		return this.active;
	}
	
	// These methods are called when component change its state.
	protected abstract void onActivation();
	protected abstract void onDeactivation();
	
	// Execute a command
	public abstract void enterNewMessage(Message message);
	
	// Attribute
	private boolean active = false;
}
